#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string>
#include <vector>
#include <pthread.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <time.h>

#define SEVPORT 4829


struct CLIENTINFO
{
  int fd;				/* client file descriptor */
  std::string name;			/* client name */
  struct sockaddr_in client_addr;	/* client socket address struct */
};


class Server
{
public:
  Server(std::string name, unsigned short sin_family, in_addr_t s_addr, unsigned short sin_port);
  ~Server(){};
  bool initialize();
  bool send_time(int client_fd);
  bool send_name(int client_fd);
  bool send_info(int client_fd);
  bool send_msg(char *name, char *forward_msg);
  bool delete_fd(int client_fd);
  friend void *request_handler(void *arg);

private:

  int server_sockfd = -1;			/* server file descriptor */
  std::string server_name = "server";		/* server name */
  struct sockaddr_in server_addr;		/* server socket address structure */
  std::vector<struct CLIENTINFO> client_infos;	/* all client infomation */
};


struct THREADPARAM
{
	struct CLIENTINFO client_info;
	Server *server;
};
